package com.csun.dsms.controller;

import com.csun.dsms.comment.core.annotation.Authorization;
import com.csun.dsms.comment.core.utils.wrapper.WrapMapper;
import com.csun.dsms.comment.core.utils.wrapper.Wrapper;
import com.csun.dsms.model.huang.HgAttachmentData;
import com.csun.dsms.model.huang.HgConsumptionData;
import com.csun.dsms.model.huang.HgQueryDto;
import com.csun.dsms.model.huang.HgYearMonthVo;
import com.csun.dsms.service.HgAttachmentDataService;
import com.csun.dsms.service.HgConsumptionDataService;
import com.csun.dsms.utils.PublicUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 附件下载
 */
@RestController
@RequestMapping("/hgAttachment")
public class HgAttachmentController {
    
    @Resource
    private HgAttachmentDataService hgAttachmentDataService;

    /*
    * 设备的添加
    * */
    @Authorization
    @RequestMapping(value = "/dataAdd",method = RequestMethod.POST)
    public Wrapper dataAdd (@RequestBody HgAttachmentData hgData){
        if(PublicUtil.isEmpty(hgData.getArea().trim())){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,"县市区不能不空");
        }
        Integer save = hgAttachmentDataService.save(hgData);
        if(save<1){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,Wrapper.ERROR_MESSAGE);
        }
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE);
    }

    /*
     * 数据查询
     * */
    @Authorization
    @RequestMapping(value = "/dataListQuery",method = RequestMethod.POST)
    public Wrapper dataListQuery (@RequestBody HgQueryDto hgQueryDto){
        List<HgAttachmentData> query = hgAttachmentDataService.queryDataList(hgQueryDto);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE,new PageInfo<>(query));
    }

    @Authorization
    @RequestMapping(value = "/dataUpdate",method = RequestMethod.POST)
    public Wrapper dataUpdate (@RequestBody HgAttachmentData hgData){
        if(PublicUtil.isEmpty(hgData.getArea().trim())){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,"县市区不能不空");
        }
        Integer save = hgAttachmentDataService.update(hgData);
        if(save<1){
            return WrapMapper.wrap(Wrapper.ERROR_CODE,Wrapper.ERROR_MESSAGE);
        }
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,Wrapper.SUCCESS_MESSAGE);
    }


}
